{! extends "base.html" !}
{! block hscript !}
	<script type="text/javascript" src="{{site.url}}js/jquery.min.js"></script>
    <script type="text/javascript" src="{{site.url}}js/jquery.form.js"></script>
    <script type="text/javascript" src="{{site.url}}ckeditor/ckeditor.js"></script>
{! endblock !}
{! block nav !}
			<a href="{{site.adminUrl}}post">All posts</a>
			{%if post %}<a href="{{site.adminUrl}}post/create">Write post</a>{%endif%}
{! endblock !}
{! block content !}
<form id="postForm" action="{{site.adminUrl}}post/{%if post %}update{%else%}add{%endif%}" method="post">
	 <div class="wrap">
      <h2>{%if post %}Edit Post{%else%}Write Post{%endif%}</h2>
      <div id="poststuff">

<div id="submitlink" class="submitbox">

<div id="previewview">
<h3>Date</h3>
<div class="inside">
<input type="text" name="date" value='{{post.date|date:"yyyy-MM-dd HH:mm:ss",site.timezone}}' />
<br />yyyy-MM-dd HH:mm:ss
</div>
</div>
<h3>Category</h3>
<div class="inside">
<p style="height:120px;overflow-y:auto">
                    {%for cat in categories%}
                       <input type="checkbox" name="categories" tabindex="7" value="{{cat.id}}" {%if post.categoryIds|contain:cat.id %}checked="checked"{%endif%}/>{{cat.name}}<br>
                    {%endfor%}
</p>
</div>

<p class="submit">
	<input type="submit" id="dosubmit" tabindex="9" value="Save" name="save" class="button button-highlighted"/>&nbsp;
	<input type="checkbox" style="margin-left:10px;" tabindex="8" value="publish" name="publish" class="button button-highlighted" {%if post.published %}checked="checked"{%endif%}/>Published
</p>

</div>

<div id="post-body2">

<div id="titlediv">
<h3>Title</h3>
<div id="titlewrap">
	<input id="title" type="text" id="title" value="{{post.title}}" tabindex="1" size="60" name="title"/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Article</h3>
<div class="editorcontainer">
	<textarea id="article" style="width: 695px;" cols="40" rows="15" tabindex="2" name="article">{{post.article}}</textarea><br/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Slogan</h3>
<div class="inside">
	<input id="slogan" type="text" value="{{post.slogan}}" tabindex="3" size="40" name="slogan"/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Tags</h3>
<div class="inside">
	<input id="tags" type="text" value="{{post.tagNames}}" tabindex="4" size="40" name="tagNames"/>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Excerpt</h3>
<div class="inside">
	<textarea id="excerpt" style="width: 675px;" cols="38" tabindex="5" name="excerpt">{{post.excerpt}}</textarea>
</div>
</div>

<div class="clear"></div>
<div class="stuffbox">
<h3>Reload</h3>
<div class="inside">
	<input id="source" type="text" value="{{post.source}}" tabindex="6" size="94" name="source"/><br/>
</div>
</div>

	<input type="hidden" value="{{post.id}}" name="id"/>
</div>
</div>	
</div>
</form>
{! endblock  !}
{! block bscript !}    
<script type="text/javascript">
var editor = CKEDITOR.replace('article', 
		{
			enterMode:2,//enter press add a <br />
			shiftEnterMode:1,//shift+enter add a <p>
			resize_minWidth : 695,
			extraPlugins : 'uicolor',
			uiColor: '#A3D5F2',
			toolbar :
				[
				    ['Source'],
				    ['Cut','Copy','Paste','PasteText','PasteFromWord'],
				    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat','-','About','UIColor'],
				    '/',
				    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
				    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
				    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
				    ['Link','Unlink','Anchor'],
				    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
				    '/',
				    ['Styles','Format','Font','FontSize'],
				    ['TextColor','BGColor'],
				    ['Maximize', 'ShowBlocks']
				]
		});

$(function() { 
    var options = {
    	    dataType: 'json',
    	    success : function(data) {
	    			var hmd = $("#hiddenMessage");
	    			if (data.type == "error") {
	    				hmd.html("<div class='error'>" + data.message + "</div>");
	    			} else {
	    				hmd.html("<div class='info'>" + data.message + "</div>");
	    				{% if post|not %}
	    				$("#title").val('');
	    				$("#slogan").val('');
	    				$("#article").val('');
	    				{% endif %} 
	    			}
	    			hmd.show().focus();
    			},
    	};
    	$("#postForm").ajaxForm(options);
    }
);

$("#dosubmit").click(function(){
	if (window.editor) {
		document.getElementById("article").value = window.editor.getData();
	}
});
</script>
{! endblock !}